<template>
    <div id="service_request_cpu_info" style="height:350px;width:100%;"/>
</template>

<script>
import echarts from 'echarts'

require('echarts/theme/macarons') // echarts theme

export default {
  name: 'ServiceRequestsCpu',
  props: ['cpuInfoChart'],
  watch: {
    cpuInfoChart: function(newVal, oldVal) {
      this.init()
    }
  },
  created() {
    this.cpuInfoChart.cpuTimeData
  },
  mounted() {
    // 监听侧边栏的变化
    this.sidebarElm = document.getElementsByClassName('sidebar-container')[0]
    this.sidebarElm && this.sidebarElm.addEventListener('transitionend', this.sidebarResizeHandler)
  },
  methods: {
    init() {
      const ServiceRequestsCpu = this.$echarts.init(document.getElementById('service_request_cpu_info'))

      const option = {
        // tooltip: {
        //   trigger: 'axis',
        //   axisPointer: {
        //     type: 'cross',
        //     label: {
        //       backgroundColor: '#6a7985'
        //     }
        //   }
        // },
        tooltip: {
          trigger: 'axis',
          backgroundColor: 'rgba(0,0,0,0.4)',
          textStyle: {
            color: '#FFFFFF'
          },
          axisPointer: {
            type: 'cross'
          },
          padding: [5, 10]
        },
        toolbox: {
          feature: {
            //saveAsImage: {}
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [{
          type: 'time',
          data: this.cpuInfoChart.cpuTimeData,
          // data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
          boundaryGap: false,
          axisTick: {
            show: false
          },
          axisLine: {
            show: false
          },
          axisLabel: {
            show: true,
            textStyle: {
              color: '#131D33'
            }
          }
        }],
        dataZoom: [
          {
            show: true, // 是否展示
            xAxisIndex: [0],  // 控制第一个x轴
            height: 15,
            left: 100,
            right: 100,
            bottom: 0,
            start: 0,  // 数据窗口范围的起始百分比。范围是：0 ~ 100。表示 0% ~ 100%。
            end: 80,  // 数据窗口范围的结束百分比。范围是：0 ~ 100。
            handleSize: '10%',
            zoomLock: true //是否锁定选择区域（或叫做数据窗口）的大小。如果设置为 true
          },
          {
            type: 'inside',  // 内置型数据区域缩放组件，用户可以在坐标系上通过鼠标拖拽、鼠标滚轮、手指滑动（触屏上）来缩放或漫游坐标系
            show: true,
            disabled: false,  // 是否停止组件的功能
            height: 15,
            left: 100,
            right: 100,
            start: 0,
            end: 80
          }
          /* {
             type: 'slider',
             show: true,
             start: 0,
             end: 70,
             handleSize: 8
           },
           {
             type: 'inside',
             start: 0,
             end: 70
           }*/
        ],
        yAxis: [{
          type: 'value',
          splitNumber: 6,
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            show: true,
            textStyle: {
              color: '#C8CCDD'
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              width: 2,
              type: [2, 20],
              dashOffset: 5
            }
          },
          splitArea: { show: false }
        }],
        series: [{
          data: this.cpuInfoChart.cpuTimeData,
          // data: [150, 230, 224, 218, 135, 147, 260],
          type: 'line',
          symbol: 'none'
        }]
      }
      ServiceRequestsCpu.setOption(option)
      window.addEventListener('resize', function() {
        ServiceRequestsCpu.resize()
      })
    }
  }
}
</script>
